# -*- coding: utf-8 -*-

#----------------------------------------------------------------------
# judge if 'elem' is in 'cont'.
#
def contains(cont, elem):
  for i in range(len(cont)):
    if elem == cont[i] :
      return True
  return False

#----------------------------------------------------------------------
# combine 'n' elements which get from 'array'.
# and combination doesn't allow duplicated elements.
#
def permute(n, array):
  if n <= 0 or n > len(array) :
    return

  all_perm = []
  perm = []
  
  for i in range(len(array)):
    if not contains(perm, array[i]):
      perm.append(array[i])
    if n == len(perm):
      if not contains(all_perm, perm):
        all_perm.append(perm)
    else:
      for j in range(i + 1, len(array)):
        if not contains(perm, array[j]):
          perm.append(array[j])
        if n == len(perm):
          perm.sort()
          if not contains(all_perm, perm):
            all_perm.append(perm)
          perm = perm[0:-1]
        j = j + 1
    i = i + 1
    perm = []
    
  return all_perm

#----------------------------------------------------------------------
# test
#arr = range(1, 21)

#perms = permute(2, arr)

#print len(perms)
#print perms
